import React from 'react'
import { observable, action, toJS, computed } from 'mobx';
import { Tools, Popover } from 'weaver-mobile'
import { SearchAdvanced, ListAdvanced, RouteLayout, Browser, BrowserHrm, Upload } from 'weaver-mobile-page';

const getLabel = Tools.getLabel;

export default class TaskDetailBaseinfoStore {

    @observable
    taskid = ""

    @observable
    columnList = []

    @action
    changeColumnList = (columnList) => {
        this.columnList = columnList
    }

    @observable canedit = false
    @observable isconfirm = false

    @observable
    editParams = {}

    @action
    changeEditparams = (editParams) => {
        this.editParams = editParams
    }

    @action
    changeEditparamsField = (fieldname, fieldvalue) => {
        this.editParams = { ...this.editParams, [fieldname]: fieldvalue }
    }

    @action
    initValues = (taskDetail) => {
        this.taskid = taskDetail.id
        this.columnList = taskDetail.columnList
        this.canedit = taskDetail.canedit
        this.isconfirm = taskDetail.isconfirm
        this.canremind = taskDetail.canremind
        this.canaudit = taskDetail.canaudit
        this.editParams.name = taskDetail.name
        this.editParams.todotype = taskDetail.todotype + "" || "4"
        this.editParams.begindate = taskDetail.begindate
        this.editParams.enddate = taskDetail.enddate
        this.editParams.remark = taskDetail.remark
        this.editParams.status = taskDetail.taskstatus
        this.editParams.level = taskDetail.lev
        this.editParams.creater = taskDetail.creater
        this.editParams.creatername = taskDetail.creatername
        this.editParams.createdate = taskDetail.createdate

        this.editParams.principalid = taskDetail.principalid || ''

        // this.editParams.parentid = taskDetail.parentid || ''
        if (taskDetail.parentid) {
            this.editParams.parentArray = [{id: taskDetail.parentid, name: taskDetail.parentname}]
        } else {
            this.editParams.parentArray = []
        }

        // this.editParams.principalid = taskDetail.principalid || ''
        if (taskDetail.principalid) {
            this.editParams.principalArray = [{id: taskDetail.principalid, name: taskDetail.principalname}]
        } else {
            this.editParams.principalArray = []
        }

        // this.editParams.partnerid = taskDetail.partnerids || ''
        this.editParams.partnerArray = taskDetail.partnerarry || []

        // this.editParams.sharerid = taskDetail.sharerids || ''
        this.editParams.sharerArray = taskDetail.sharerarry || []

        this.editParams.tagArray = taskDetail.tagarry || []
        // this.editParams.tagArray.push({
        //     id: 1,
        //     name: "test"
        // })

        this.editParams.risk = taskDetail.risk
        this.editParams.difficulty = taskDetail.difficulty
        this.editParams.assist = taskDetail.assist

        this.editParams.showallsub = taskDetail.showallsub
    }

    @observable
    todoTypeOptions = [
        {
            key: "1",
            showname: getLabel(15537,'今日')
        },{
            key: "2",
            showname: getLabel(22488,'明天')
        },{
            key: "3",
            showname: getLabel(382509,'即将')
        },{
            key: "4",
            showname: getLabel(382499,'不标记')
        },{
            key: "5",
            showname: getLabel(382498,'备忘')
        }
    ]

    @observable
    urgentLevelOptions = [
        {
            key: "0",
            showname: getLabel(15808, '未设置')
        },{
            key: "1",
            showname: getLabel(382501, '重要紧急')
        },{
            key: "2",
            showname: getLabel(382502, '重要不紧急')
        },{
            key: "3",
            showname: getLabel(382503, '不重要紧急') 
        },{
            key: "4",
            showname: getLabel(382504, '不重要不紧急')
        }
    ]

    @action
    getOptions = (columnarray) => {
        if (columnarray === "tododatas") {
            return this.todoTypeOptions
        } else if (columnarray === "urgent") {
            return this.urgentLevelOptions
        }
        return []
    }

    @observable
    showContentDelIcon = false

    @action
    changeShowContentDelIcon = (showContentDelIcon) => {
        this.showContentDelIcon = showContentDelIcon
    }

    @computed
    get taskDetailSupTaskBrowserStore () {
        return new Browser.Store({ route: '/taskHome/taskDetail/' + this.taskid })
    }

    @computed
    get taskDetailHrmPrincipalBrowserStore () {
        return new BrowserHrm.Store({ route: '/taskHome/taskDetail/' + this.taskid })
    }

    @computed
    get taskDetailHrmPartnerBrowserStore () {
        return new BrowserHrm.Store({ route: '/taskHome/taskDetail/' + this.taskid })
    }

    @computed
    get taskDetailHrmSharerBrowserStore () {
        return new BrowserHrm.Store({ route: '/taskHome/taskDetail/' + this.taskid })
    }

    @computed
    get taskDetailTagBrowserStore () {
        return new Browser.Store({ route: '/taskHome/taskDetail/' + this.taskid })
    }
}